//++++++++++++++++++++++++++++++++++++++++
// 《Go Web编程实战派从入门到精通》源码
//++++++++++++++++++++++++++++++++++++++++
// Author:廖显东（ShirDon）
// Blog:https://www.shirdon.com/
// 仓库地址：https://gitee.com/shirdonl/goWebActualCombat
// 仓库地址：https://github.com/shirdonl/goWebActualCombat
//++++++++++++++++++++++++++++++++++++++++

package main

import (
	"fmt"
	"github.com/gomodule/redigo/redis"
	"io/ioutil"
	"net/http"
	"strings"
	"time"
)

var pool *redis.Pool

func init() {
	pool = &redis.Pool{
		MaxIdle:     16,
		MaxActive:   1024,
		IdleTimeout: 300,
		Dial: func() (redis.Conn, error) {
			return redis.Dial("tcp", "localhost:6379")
		},
	}
}
func main() {
	for {
		time.Sleep(time.Second * 10)
		fmt.Println("已经4秒了")
		get()
	}
}
func get() {
	url := "https://stock.xueqiu.com/v5/stock/history/trade.json?symbol=SZ002617&count=1"
	payload := strings.NewReader("")
	req, err := http.NewRequest("GET", url, payload)
	req.Header.Add("Cookie", "xq_a_token=92d0f5c8a64407bc997a9c96d787d5c1a3a62abb; xqat=92d0f5c8a64407bc997a9c96d787d5c1a3a62abb; xq_r_token=21b1ccf01dd825578c48545867ba54eacdb130d4; xq_id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1aWQiOi0xLCJpc3MiOiJ1YyIsImV4cCI6MTY0NzU1ODc1OSwiY3RtIjoxNjQ1NzY2OTIzNTkzLCJjaWQiOiJkOWQwbjRBWnVwIn0.KDeMBBeMf8lunJ5ctYTJpyS01uY57KJizdeWckDNeEtC7R8jNvkvXw8BhVuWFZTpX5QyWBZo5Y_A_1kmv64UkTzk6yyNap-ubYNq1L42l-8a-QB_OdV3YTu9fGp94ajK_fuhDQDayyZZryCR9zzW-FdA255VdJSc8XqhzwV9gNaQGP_15u99X6eUg5jla6qDqcQTaguc17fKG0Le2WNay6a42bt0llG-2hU2xu0nLBdr09wod55OUmTzmjyeFZaFPNmMgy1KwQ8wBLcuBnxwLNlAGqeRIeFJ3r3RNZd0P_s1m4O__sXLU7x5OLxL1-Sr4P20W6947v56n_eaAJHR4Q; u=591645766956178; device_id=71d09c072a9174e96a459ae92dbb031c; Hm_lvt_1db88642e346389874251b5a1eded6e3=1645766965; Hm_lpvt_1db88642e346389874251b5a1eded6e3=1645767131")
	//resp,err:=http.Get("")
	resp, _ := http.DefaultClient.Do(req)
	defer resp.Body.Close()
	if err != nil {
		fmt.Print("err", err)
	}
	closer := resp.Body
	bytes, err := ioutil.ReadAll(closer)
	setRedis(bytes)
}
func setRedis(bytes []byte) {
	c := pool.Get()
	defer c.Close()
	_, err := c.Do("Set", "bytes", bytes)
	_, err = c.Do("expire", "bytes", 10)
	if err != nil {
		fmt.Println(err)
		return
	}
}
